package com.spzx.order.configure;

import com.spzx.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author Haoran Sun
 * @since 2024/08/02
 */

@Configuration
public class CancelOrderConfig {

    @Bean
    public Queue cancelQueue() {
        return new Queue(MqConst.QUEUE_CANCEL_ORDER, true);
    }
    @Bean
    public CustomExchange cancelExchange(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER, "x-delayed-message", true, false, map);
    }
    @Bean
    public Binding bindingCancel(){
        return BindingBuilder.bind(cancelQueue())
                .to(cancelExchange())
                .with(MqConst.ROUTING_CANCEL_ORDER)
                .noargs();
    }

}
